define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mall/goods/appraise/index',
                    //add_url: 'mall/goods/appraise/add',
                    //edit_url: 'mall/goods/appraise/edit',
                    //del_url: 'mall/goods/appraise/del',
                    //multi_url: 'mall/goods/appraise/multi',
                    table: 'mall_goods_appraise',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'shop_id', title: __('Shop_id'),visible:false},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'ordergoods_id', title: __('Ordergoods_id'),visible:false},
                        {field: 'goods_id_text', title: __('Goods_id')},
                        {field: 'goodsspec_id', title: __('Goodsspec_id'),visible:false},
                        {field: 'user_id', title: __('User_id'),visible:false},
                        {field: 'goodsraty', title: __('Goodsscore'), formatter: Controller.api.formatter.score},
                        {field: 'serviceraty', title: __('Servicescore'), formatter: Controller.api.formatter.score},
                        {field: 'timeraty', title: __('Timescore'), formatter: Controller.api.formatter.score},
                        {field: 'showis', title: __('Showis'), searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.toggle},
                        {field: 'status', title: __('Status'), searchList: {"best":__('Status best'),"good":__('Status good'),"bad":__('Status bad')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'replytime', title: __('Replytime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                score: function (value, row, index) {
                    var stars=[];
                    for(i=1;i<=5;i++){
                        if(i<=value){
                            stars[i]='<i class="fa fa-star"></i>'
                        }else{
                            stars[i]='<i class="fa fa-star-o"></i>'
                        }
                    }
                    return '<div class="rating">'+stars.join("")+'</div>';
                },
            }
        }
    };
    return Controller;
});